package cuiyt.leetcode.tree;

import cuiyt.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 二叉树前序遍历
 */
public class T144二叉树的前序遍历 {

    /**
     * 左 中 右 进行递归遍历
     * @param args
     */
    public static void main(String[] args) {
        TreeNode root = new TreeNode();
        ArrayList<Integer> list = new ArrayList<>();
        printTreeByLeft(root, list);
        System.out.println(list);
    }

    public static void printTreeByLeft(TreeNode node,  ArrayList<Integer> list){
        if(Objects.isNull(node)){
            return;
        }
        int val = node.val;
        list.add(val);
        printTreeByLeft(node.left,list);
        printTreeByLeft(node.right,list);
    }
}
